<?php
function getCode($type=1,$lenstr=4)
{
    $str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    if($type==1){
        $len = 9;//下标值；
    }else if($type==2){
        $len = 35;
    }else if($type==3){
        $len = strlen($str)-1;
    }
    $code="";
    for($i=0;$i<$lenstr;$i++){
        for(;;){
            $s = $str[rand(0,$len)];//随机产生一个字符赋值给$s;
            if(substr_count($code,$s)==0){
                $code.=$s;
                break;
            }
        }
    }
    return $code;
}